package MyLinkedList;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;

public class Test {

    public static void main(String[] args) {
        LinkedList<Integer> list=new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        System.out.println(list);
        System.out.println("=========");
        for(Integer x:list) {
            System.out.print(x+" ");
        }
        System.out.println();
        System.out.println("==========");

//        int size=list.size();
//        for(int i=0;i<size;i++) {
//            System.out.print(list.get(i)+" ");
//            list.remove(i);
//        }
//        System.out.println();
//        System.out.println("======");
        Iterator<Integer> it=list.iterator();
        while(it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();

        System.out.println("=========");

        ListIterator<Integer> it2=list.listIterator(list.size());
        while(it2.hasPrevious()) {
            System.out.print(it2.previous()+" ");
        }
        System.out.println();
    }



    public static void main1(String[] args) {
        MyLinkedList ml=new MyLinkedList();
        ml.addFirst(1);
        ml.addFirst(2);
        ml.addFirst(3);
        ml.display();
        ml.addLast(4);
        ml.addLast(5);
        ml.addLast(6);
        ml.display();
        System.out.println("==========");
        ml.addIndex(0,100);
        ml.addIndex(5,100);
        System.out.println(ml.size());
        ml.addIndex(8,100);
        ml.display();
        ml.removeAllKey(100);
        ml.display();
    }
}
